<template>
  <el-row class="wrap">
    <el-col :span="24" class="warp-breadcrum">
      <el-breadcrumb>
        <el-breadcrumb-item>首页</el-breadcrumb-item>
        <el-breadcrumb-item>代码生成</el-breadcrumb-item>
      </el-breadcrumb>
    </el-col>
    <el-col :span="24" class="wrap-main">
      <el-form size="small" :inline="true">
        <el-form-item>
          <el-input></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="tableRows" border size="small">
        <el-table-column label="类型" prop="engine"></el-table-column>
        <el-table-column label="表名字" prop="tableName"></el-table-column>
        <el-table-column label="注释" prop="tableComment"></el-table-column>
        <el-table-column label="创建日期" prop="createTime"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="downFile(scope.row.tableName)" size="mini" type="success">下载</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-col>
    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination layout="total,prev, pager, next" @current-change="search" :page-size="limit"
                     :total="total"
                     style="float:right;">
      </el-pagination>
    </el-col>
  </el-row>
</template>

<script>
  import API from '../../api/api_generator'

  export default {
    name: "List",
    data() {
      return {
        limit: 10,
        page: 1,
        total: 0,
        tableRows: [],
        uploadUrl: '',
        uploadData: {},
        uploadHeaders: {Authorization: ''}
      }
    },
    methods: {
      search: function (val) {
        let that = this
        let params = {
          limit: that.limit,
          page: val
        }
        this.page = val
        API.list(params).then(res => {
            that.tableRows = res
        })
      },
      downFile: function (val) {
        let base = process.env.API_ROOT
        location.href = `${base}/api-cms/templates/common/generator/code/${val}`
      }
    },

    mounted() {
      this.search(1);
    }
  }
</script>

<style scoped>

</style>
